package com.hollysys.usersync.constant;

import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Optional;

/**
 * 同步请求操作类型枚举
 */
public enum RequestOptionEnum {

    /**
     * 动作枚举
     */
    CREATE("create", "添加"),
    UPDATE("update", "更新"),
    DELETE("delete", "删除");

    /**
     * 枚举值
     */
    @JsonValue
    private final String value;

    /**
     * 接口描述
     */
    private final String description;

    /**
     * 获得指定枚举值对象
     *
     * @param value 枚举值
     * @return 枚举值对象
     */
    public static Optional<RequestOptionEnum> getEnumByValue(String value) {
        for (RequestOptionEnum optionEnum : RequestOptionEnum.values()) {
            if (optionEnum.getValue().equals(value)) {
                return Optional.of(optionEnum);
            }
        }
        return Optional.empty();
    }

    RequestOptionEnum(String value, String description) {
        this.value = value;
        this.description = description;
    }

    public String getValue() {
        return value;
    }

    public String getDescription() {
        return description;
    }
}
